<template>
  <div>
    <div class="detail-block" v-if="current === 'PA'">
      <p v-if="!isCredit"></p>
      <p v-if="!isCredit" style="text-align: right">
        <el-button
          type="primary"
          size="small"
          @click="updateZtData"
          :disabled="disableUpdateBtn"
          :loading="loadingBtn"
          >{{ textBtn }}</el-button
        >
      </p>
    </div>
    <div class="box">
      <div class="title-scroll">企业名称</div>
      <div class="title-scroll">
        {{ baseInfo.tenantName || '&#45;&#45;' }}
      </div>

      <div class="title-scroll">企业信用代码</div>
      <div class="title-scroll">
        {{ baseInfo.uscCode || '&#45;&#45;' }}
      </div>
    </div>
    <div class="box">
      <div class="title-scroll">首次退税申报时间距今月份</div>
      <div class="title-scroll">
        {{ riskInfoRsp.firstDrawbackMonths || '&#45;&#45;' }}
      </div>

      <div class="title-scroll">上年度纳税申报表销售额</div>
      <div class="title-scroll">
        {{ riskInfoRsp.y1TaxSellAmt || '&#45;&#45;' }}
      </div>
    </div>
    <div class="box">
      <div class="title-scroll">上年度纳税申报表销售额同比</div>
      <div class="title-scroll">
        {{ riskInfoRsp.y1TaxSellAmtDownRate || '&#45;&#45;' }}
      </div>

      <div class="title-scroll">上上年度纳税申报表销售额同比</div>
      <div class="title-scroll">
        {{ riskInfoRsp.y2TaxSellAmtDownRate || '&#45;&#45;' }}
      </div>
    </div>
    <div class="box">
      <div class="title-scroll">上年度纳税申报表出口额同比</div>
      <div class="title-scroll">
        {{ riskInfoRsp.y1TaxExportAmtDownRate || '&#45;&#45;' }}
      </div>

      <div class="title-scroll">上上年度纳税申报表出口额同比</div>
      <div class="title-scroll">
        {{ riskInfoRsp.y2TaxExportAmtDownRate || '&#45;&#45;' }}
      </div>
    </div>
    <div class="box">
      <div class="title-scroll">近12月成功退税次数</div>
      <div class="title-scroll">
        {{ riskInfoRsp.m12DrawbackNum || '&#45;&#45;' }}
      </div>

      <div class="title-scroll">近12月暂缓退税和不予退税占比</div>
      <div class="title-scroll">
        {{ riskInfoRsp.m12DrawbackFailRate || '&#45;&#45;' }}
      </div>
    </div>
    <div class="box">
      <div class="title-scroll">超期未缴或少缴税款</div>
      <div class="title-scroll">
        {{ riskInfoRsp.unpaidTaxAmt || '&#45;&#45;' }}
      </div>

      <div class="title-scroll">与核心企业合作月数</div>
      <div class="title-scroll">
        {{ riskInfoRsp.coopMonths || '&#45;&#45;' }}
      </div>
    </div>
    <div class="box">
      <div class="title-scroll">企业成立月数</div>
      <div class="title-scroll">
        {{ riskInfoRsp.scorpFoundMon || '&#45;&#45;' }}
      </div>

      <div class="title-scroll">经营场所所在省份</div>
      <div class="title-scroll">
        {{ riskInfoRsp.businessProvince || '&#45;&#45;' }}
      </div>
    </div>
    <div class="box">
      <div class="title-scroll">最近12个月出口退税金额</div>
      <div class="title-scroll">
        {{ riskInfoRsp.transactAmt1 || '&#45;&#45;' }}
      </div>

      <div class="title-scroll">上年度出口退税金额</div>
      <div class="title-scroll">
        {{ riskInfoRsp.transactAmt2 || '&#45;&#45;' }}
      </div>
    </div>
    <div class="box">
      <div class="title-scroll">是否国税一、二、三类出口企业</div>
      <div class="title-scroll">
        {{ (riskInfoRsp.customerType == 1 ? '是' : '否') || '&#45;&#45;' }}
      </div>

      <div class="title-scroll">是否位于税务风险黑名单中</div>
      <div class="title-scroll">
        {{ (riskInfoRsp.coopContractDisputes == 1 ? '是' : '否') || '&#45;&#45;' }}
      </div>
    </div>
    <div class="box">
      <div class="title-scroll">是否核心企业关联人</div>
      <div class="title-scroll">
        {{ (riskInfoRsp.ifRelateCompany == 1 ? '是' : '否') || '&#45;&#45;' }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CompanyInfo',
  props: {
    baseInfo: Object,
    riskInfoRsp: Object,
    isCredit: Boolean,
    disableUpdateBtn: Boolean,
    current: String,
  },
  data() {
    return {
      textBtn: '数据刷新',
      loadingBtn: false,
      logoutTypeObj: {
        Y: '注销',
        N: '正常',
      },
    }
  },
  methods: {
    /****
     *
     * @returns {Promise<void>}
     */
    async updateZtData() {
      this.loadingBtn = true
      const res = await this.$http.post('/risk/updateZtInfo?uscCode=' + this.baseInfo.uscCode, {}, { isLoading: false })

      if (res === '-1') {
        this.textBtn = '数据刷新'
        this.$message.error('数据刷新失败!')
        this.loadingBtn = false
      } else if (res === '1') {
        this.textBtn = '数据刷新'
        this.$message.success('数据刷新成功!')
        this.loadingBtn = false
      } else if (res === '0') {
        this.textBtn = '数据刷新中...'
        await this.delay(30000)
        await this.updateZtData()
      }
    },

    delay(time) {
      return new Promise(resolve => setTimeout(resolve, time))
    },
  },
}
</script>

<style lang="scss" scoped>
.detail-block {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  color: $gray;
  font-size: $f-s-16;
  margin-bottom: 8px;
  > p {
    width: 50%;
    margin-bottom: 10px;
  }
}
.box {
  @include flex();
  flex-wrap: wrap;
  border-left: 1px solid $gray-lighter;
  border-top: 1px solid $gray-lighter;
  border-right: 1px solid $gray-lighter;
  &:last-child {
    border-bottom: 1px solid $gray-lighter;
  }

  > div {
    width: 25%;
    height: 40px;
    text-align: center;
    line-height: 40px;
    color: $gray;
    &:not(:nth-child(4n)) {
      border-right: 1px solid $gray-lighter;
    }
    &:first-child,
    &:nth-child(3) {
      background-color: #fafafa;
    }
  }
}
.title-scroll {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  -o-text-overflow: ellipsis;
}
</style>
